package com.location.footprint.adapter;

import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;

import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.location.footprint.R;
import com.location.footprint.base.BaseAppAplication;
import com.location.footprint.bean.CommentsChildBean;


public class CommentsChildAdapter extends BaseQuickAdapter<CommentsChildBean, BaseViewHolder> {
    public CommentsChildAdapter() {
        super(R.layout.item_child_comments, null);
    }

    @Override
    protected void convert(BaseViewHolder helper, CommentsChildBean item) {
        int color=BaseAppAplication.theme;
        if (color==R.color.black){
            color=R.color.deep_blue;
        }
        String[] names = item.getNickName().split(",");
        SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
        stringBuilder.append(names[0]);
        ForegroundColorSpan colorGreen = new ForegroundColorSpan(ContextCompat.getColor(mContext, color));
        stringBuilder.setSpan(colorGreen, 0, stringBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        if (names.length == 2) {
            stringBuilder.append("回复");
            ForegroundColorSpan colorBlack = new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.text_default));
            stringBuilder.setSpan(colorBlack, stringBuilder.length() - 2, stringBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            stringBuilder.append(names[1]);
            ForegroundColorSpan colorGreen1 = new ForegroundColorSpan(ContextCompat.getColor(mContext, color));
            stringBuilder.setSpan(colorGreen1, stringBuilder.length() - names[1].length(), stringBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        }
        int index = stringBuilder.length();
        stringBuilder.append(" : ");
        stringBuilder.append(item.getComments());
        ForegroundColorSpan colorBlack = new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.text_default));
        stringBuilder.setSpan(colorBlack, index, stringBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);

        helper.setText(R.id.text_child_comments, stringBuilder);
//        ImageView imageView = helper.getView(R.id.image);
//        imageView.setBackgroundResource(item.getImage());
//        GlideUtils.loadImageViewSize(this.mContext, item.getImage(), Utils.dip2px(65, this.mContext), Utils.dip2px(130, this.mContext), imageView);
    }


}
